/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ipo.mm.web.util;

import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author makcro
 */
public class UTFEncoder {

    public static String encode(String iso88591String){

        String utfString = null;

        try {
            if(iso88591String != null){
                utfString = new String(iso88591String.getBytes(ConstantManager.ENCODING_ISO88591), ConstantManager.ENCODING_UTF8);
            }
            
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(UTFEncoder.class.getName()).log(Level.SEVERE, null, ex);
        }
        return utfString;
    }

     public static String decode(String utf8String){

        String iso88591String = null;

        try {
            if(utf8String != null){
                iso88591String = new String(utf8String.getBytes(ConstantManager.ENCODING_UTF8), ConstantManager.ENCODING_ISO88591);
            }

        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(UTFEncoder.class.getName()).log(Level.SEVERE, null, ex);
        }
        return iso88591String;
    }

     public static String clearSerbianLetters(String word){
         if(word!=null){
             word = encode(word);
             word.replace("ć", "c");
             word.replace("Č", "C");
             word.replace("Ć", "C");
             word.replace("č", "c");
             word.replace("ž", "z");
             word.replace("Ž", "Z");
             word.replace("š", "s");
             word.replace("Š", "S");
             word.replace("đ", "d");
             word.replace("Đ", "D");
         }
         return word;

     }
    
}
